/*


*/

#include "GLHelpers.h" 

/* int setupGLTexture char* int int int
 * Function loads image from buffer into
 * OpenGL texture.
 */
int setupGLTexture(char *image, int width, int height, int texName) 
{
	
	if (image == 0)
    {
		return 0;
    }
	
	printf("(loadTexture) width: %d height: %d\n", width, height); 
	
	/* create a new texture object
	 * and bind it to texname (unsigned integer > 0)
	 */
	glBindTexture(GL_TEXTURE_2D, texName);
	glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
	glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
	glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, 
				 GL_RGB, GL_UNSIGNED_BYTE, image);
	
	return 1; 
};

void drawFace(int x,int y,int z,int x2,int y2,int z2  ,int x3,int y3,int z3, int textureID)
{
    glEnable (GL_TEXTURE_2D);
    glBindTexture (GL_TEXTURE_2D, textureID);	
	
	glBegin (GL_TRIANGLES);
	glTexCoord2f (0.0f,1.0f);
	glVertex3i (x, y, z);
	glTexCoord2f (1.0f, 1.0f); 
	glVertex3i (x2, y2, z2);
	glTexCoord2f (1.0f, 0.0f);
	glVertex3f (x3, y3, z3);
	glEnd();
};


